//
//  KiwipenCommand.m
//  BlueToothDemo
//
//  Created by US bike on 2017/8/29.
//  Copyright © 2017年 奇异果. All rights reserved.
//

#import "KiwipenCommand.h"
#import "KiwipenProtocol.h"
#import "Tools.h"

@implementation KiwipenCommand

+ (instancetype) CreateCommondWitCommandType:(CommandType) type{
    KiwipenCommand *cmd = [KiwipenCommand new];
    cmd.commandType = type;
    
    
    if (type == CommandTypePower) {
        Byte bytes[5] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_POWER, CMD_OPERATOR_POWER, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:5];
        
    } else if (type == CommandTypeUUID) {
        Byte bytes[5] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_UUID, CMD_OPERATOR_UUID, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:5];
        
    } else if (type == CommandTypeLED_ALL_RESET) {
        Byte crc = [Tools xorsBytes:CMD_OPERATOR_LED, LED_ALL,LED_STATUS_RESET, nil];
        Byte bytes[7] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_LED, LED_ALL, LED_STATUS_RESET, crc, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:7];
        
    } else if (type == CommandTypeLED_ALL_OFF) {
        Byte crc = [Tools xorsBytes:CMD_OPERATOR_LED, LED_ALL,LED_STATUS_OFF, nil];
        Byte bytes[7] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_LED, LED_ALL, LED_STATUS_OFF, crc, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:7];
        
    } else if (type == CommandTypeLED_ALL_ON) {
        Byte crc = [Tools xorsBytes:CMD_OPERATOR_LED, LED_ALL,LED_STATUS_ON, nil];
        Byte bytes[7] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_LED, LED_ALL, LED_STATUS_ON, crc, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:7];
        
    } else if (type == CommandTypeLED_ALL_SLOW_FLASHING) {
        Byte crc = [Tools xorsBytes:CMD_OPERATOR_LED, LED_ALL,LED_STATUS_SLOW_FLASHING, nil];
        Byte bytes[7] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_LED, LED_ALL, LED_STATUS_SLOW_FLASHING, crc, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:7];
        
    } else if (type == CommandTypeLED_ALL_FAST_FLASHING) {
        Byte crc = [Tools xorsBytes:CMD_OPERATOR_LED, LED_ALL,LED_STATUS_FAST_FLASHING, nil];
        Byte bytes[7] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_LED, LED_ALL, LED_STATUS_FAST_FLASHING, crc, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:7];
        
    } else if (type == CommandTypeLED_ALL_BREATHINGG) {
        Byte crc = [Tools xorsBytes:CMD_OPERATOR_LED, LED_ALL,LED_STATUS_BREATHING, nil];
        Byte bytes[7] = {CMD_Begin1, CMD_Begin2, CMD_OPERATOR_LED, LED_ALL, LED_STATUS_BREATHING, crc, CMD_END};
        cmd.commandData = [NSData dataWithBytes:bytes length:7];

    } else {
        cmd.commandType = CommandTypeError;
    }
    
    
    return cmd;
}

- (NSString *) description {

    return [NSString stringWithFormat:@"KiwipenCommand: type = %lu, data = %@",(unsigned long)_commandType, _commandData];
}


@end
